package com.gd.luxiaoyu.moduels.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gd.luxiaoyu.Constant;
import com.gd.luxiaoyu.moduels.entity.CustomerTableEntity;
import com.gd.luxiaoyu.moduels.service.CustomerTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("right/customertable")
public class CustomerTableController {
    @Autowired
    private CustomerTableService customerTableService;
    Constant constant =new Constant();

    /**
     * 列表
     */
    @RequestMapping("/QueryAll")
    @ResponseBody
    public Map<String ,Object> QueryAll(Page<CustomerTableEntity> customerTableEntityPage,CustomerTableEntity customerTableEntity){
        IPage<CustomerTableEntity> page = customerTableService.getOAllCustomer(customerTableEntityPage,customerTableEntity);
        Map<String ,Object> map = new HashMap<>();
        map.put("toals",page.getTotal());
        map.put("rows",page.getRecords());
        System.out.println("=========================成功===========================");
        return map;
    }

    /*
    * 通过开发商的id查询
    * */
     @RequestMapping("queryById")
     @ResponseBody
    public CustomerTableEntity queryById(CustomerTableEntity customerTableEntity){
        CustomerTableEntity customerTableEntity1 = customerTableService.getById(customerTableEntity.getId());
        return  customerTableEntity;
    }


    /*
    * 开发商修改基本信息
    * */
    @RequestMapping("Update")
    @ResponseBody
    public R<?> Update(CustomerTableEntity customerTableEntity){
        boolean update = customerTableService.updateById(customerTableEntity);
        return  update ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }

    /*
    * 插入新的开发商
    * */
    @PostMapping("save")
    @ResponseBody
    public R<?> save(CustomerTableEntity customerTableEntity){
        boolean save = customerTableService.save(customerTableEntity);
        return save ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }


    /*
    * 删除或者注销开发商
    * */
    @RequestMapping("delete")
    @ResponseBody
    public R<?> delete(CustomerTableEntity customerTableEntity){
        boolean delete = customerTableService.removeById(customerTableEntity.getId());
        return  delete ? R.ok(constant.SUCCESSFUL) :R.failed(constant.FAIL);
    }

}
